package org.mtmi.ui.drawables;

import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Path;
import org.mtmi.ui.scenes.COLOR;

/**
 * Display an image of knob dots color .
 */
public class KnobDotColorDrawable extends AbstractColorDrawable
{
	/** caller is responsible to dispose color */
	public KnobDotColorDrawable( Color clr ) {
		super( clr );
	}
	
	@Override
	public void paint( GC gc, int x, int y, int width, int height, int state ) {
		//a square:
		int r = Math.min( width, height );
		int r2 = r/2;
		
		int cx = x+r;
		int cy = y+r;
		
		gc.setAntialias( SWT.ON );
		
		Path p = new Path( gc.getDevice() );
		p.addArc( cx-r, cy-r, 2*r, 2*r, 180, -90 );
		p.addArc( cx-r2, cy-r2, 2*r2, 2*r2, 90, 90 );
		p.close();
		
		gc.setBackground( COLOR.grey50 );
		gc.fillPath( p );
		
		gc.setForeground( COLOR.grey20 );
		gc.setLineWidth( 2 );
		gc.drawPath( p );
		
		//TODO: draw dot
		int r4 = 7*r/8;
		int r5 = 5*r/8;
		double da = Math.PI/8;
		gc.setLineWidth( 2 );
		gc.setForeground( color );
		for( double a=Math.PI/2+da; a<Math.PI; a+=da ) {
			double cs = Math.cos( a );
			double sn = Math.sin( a );
			int x1 = cx + (int)Math.round(r4*cs); 
			int y1 = cy - (int)Math.round(r4*sn); 
			int x2 = cx + (int)Math.round(r5*cs); 
			int y2 = cy - (int)Math.round(r5*sn);
			gc.drawLine( x1, y1, x2, y2 );
		}
		p.dispose();
		
		gc.setForeground( COLOR.red );
		gc.drawLine( cx-5,cy,cx+5,cy );
		gc.drawLine( cx,cy-5,cx,cy+5 );
	}

}
